package org.example.design.search;

import java.util.ArrayList;
import java.util.List;


/**
 * @Auther:Liu
 * @Testname:LotteryTicketSubject
 * @Date:2025/8/15 11:48
 */
// 彩票的主题
public  class LotteryTicketSubject implements Subject {


    private List<Observer> observers = new ArrayList<>();

    private int number;

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }


    @Override
    public void notifyObservers() {
        number = (int) (Math.random() * 33 + 1);
        for (Observer observer : observers) {
            observer.update(number);
        }
    }
}